<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" icon="el-icon-plus" @click="sendEvent">新增退租</el-button>
				
				<el-button type="danger" plain icon="el-icon-delete" :disabled="selection.length === 0"
						   @click="batch_del"></el-button>
			</div>
			<div class="right-panel">
				
				<div class="right-panel-search">
					<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="输入企业名称"></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange"  stripe remoteSort remoteFilter>
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column label="#" type="index" width="80"></el-table-column>
				<el-table-column label="退租企业" prop="enterprise_id"  :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="退租日期" prop="checkout_date" :show-overflow-tooltip="true">
				</el-table-column>
				<el-table-column label="情况说明" :show-overflow-tooltip="true">
					<template #default="scope">
							<span v-html="scope.row.notepad"></span>
					</template>
				</el-table-column>
				<el-table-column label="负责人" prop="user_join_name" :show-overflow-tooltip="true">
				</el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="250">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">
								查看
							</el-button>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">
								编辑
							</el-button>
							<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>
	<finishDialog v-if="dialog.finish" ref="finishDialog" @success="handleSaveSuccess" @closed="dialog.finish=false"></finishDialog>
	<recordDetails v-if="dialog.detailsSave" ref="recordDialog" @closed="dialog.detailsSave=false"></recordDetails>
	<processDialog v-if="dialog.processSave" ref="processDialog" @closed="dialog.processSave=false"></processDialog>

</template>
<script>
import scSelectFilter from '@/components/scSelectFilter'
import selectUserDialog from "@/views/module/selectUserDialog";
import saveDialog from '@/views/attractinvestment/spacePlan/renting.vue'
import recordDetails from "./details";
import finishDialog from './finish'
import processDialog from './process'
    export default {
		components: {
		saveDialog,
		scSelectFilter,
		selectUserDialog,
		finishDialog,
		recordDetails,
		processDialog
	},
        data() {
            return {
				dialog: {
				save: false,
				detailsSave: false,
				finish:false
			},
			filterData: [
			],
                apiObj:this.$API.attractinvestment.checkoutManage.getCheckoutList,
				selection: [],
			search: {
				date: '',
				type: '',
				status: '',
				status1: '',
				status2: '',
				status3: '',
				handedUser: '',
				keyword: null
			}
            }
        },
		methods: {
		isValid(data){
			if (Object.prototype.toString.call(data) === '[object Undefined]') {
				return false
			}
			if (Object.prototype.toString.call(data) === '[object Null]') {
				return false
			}
			return true
		},
		checkinFormat(row, column){
			return this.isValid(row.checkin_date) ? row.checkin_date.split('T')[0] : '-'
		},
		validDateFormat(row, column){
			return this.isValid(row.valid_date) ? row.valid_date.split('T')[0] : '-'
		},
		checkoutDateFormat(row, column){
			return this.isValid(row.checkout_date) ? row.checkout_date.split('T')[0] : '-'
		},
		updateTimeFormat(row, column){
			return this.isValid(row.update_time) ? row.update_time.split('.')[0].split('T').join(' ') : '-'
		},
		async getSupervisionConfigForSelect() {
			var res = await this.$API.attractinvestment.building.getBuildingUsageById.get({id:12});
			if (res.code == 200) {
				// this.filterData[1].options = this.filterData[1].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//添加
		sendEvent() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open()
			})
		},
		//编辑
		table_edit(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
		setFinishStatus(row)
		{
			this.dialog.finish = true
			this.$nextTick(() => {
				this.$refs.finishDialog.open().setData(row);
			})
		},
		setProcess(row)
		{
			this.dialog.processSave = true
			this.$nextTick(() => {
				this.$refs.processDialog.open().setData(row);
			})
		},
		//查看
		table_show(row) {
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.recordDialog.open().setData(row)
			})
		},
		//删除
		async table_del(row) {
			var res = await this.$API.attractinvestment.checkoutManage.deleteCheckout.post({id: row.id});
			if (res.code == 200) {
				this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//批量删除
		async batch_del() {
			await this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
				type: 'warning'
			}).then(async () => {
				var checkinIdArr = [];
				for (var i = 0; i < this.selection.length; i++) {
					checkinIdArr.push(this.selection[i].id);
				}
				const loading = this.$loading();
				var res = await this.$API.attractinvestment.checkoutManage.deleteCheckoutByIds.post({ids: checkinIdArr});
				if (res.code == 200) {
					this.$refs.table.refresh()
					this.$message.success(res.message)
				} else {
					this.$alert(res.message, "提示", {type: 'error'})
				}
				loading.close();
			}).catch(() => {

			})
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		filterChange(data) {
			this.search.date = data.date;
			this.search.type = data.type;
			this.search.status = data.status;
			this.search.status1 = data.status1;
			this.search.status2 = data.status2;
			this.search.status3 = data.status3;
			this.search.status4 = data.status4;
			this.search.status5 = data.status5;
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSaveSuccess() {
			this.$refs.table.refresh()
		},
	}
    }
</script>